package studentManage;

import java.util.Scanner;

import Util.TestUtil;
import studentManage.util.MajorUtil;
import studentManage.util.StudentUtil;

public class StudentTest {

	static Scanner sc = new Scanner(System.in);

	/**
	 * 首页
	 */
	public void home() {
		MajorUtil maj = new MajorUtil();
		while (true) {
			System.out.println("**********************");
			System.out.println("请选择：");
			System.out.println("1-学生登录");
			System.out.println("2-管理员登录");
			System.out.println("3-退出系统");
			System.out.println("**********************");

			int key = TestUtil.abnormal();

			if (key == 3)
				break;

			switch (key) {
			case 1:
				stuStart();
				break;
			case 2:
				maj.login();
				break;
			default:
				break;
			}
		}
	}

	/**
	 * 管理员首页
	 */
	public void manHome() {
		while (true) {
			System.out.println("**********************");
			System.out.println("请选择：");
			System.out.println("1-学生管理");
			System.out.println("2-专业管理");
			System.out.println("3-退出");
			System.out.println("**********************");

			int key = TestUtil.abnormal();

			if (key == 3)
				break;

			switch (key) {
			case 1:
				stuHome();
				break;
			case 2:
				majHome();
				break;
			default:
				break;
			}
		}
	}

	/**
	 * 管理员
	 * 
	 * 专业管理
	 */
	public void majHome() {
		MajorUtil majorUtil = new MajorUtil();
		while (true) {
			System.out.println("**********************");
			System.out.println("请选择：");
			System.out.println("1-查看所有专业信息");
			System.out.println("2-查找专业信息");
			System.out.println("3-修改专业名称");
			System.out.println("4-退出登录");
			System.out.println("**********************");
			int key = TestUtil.abnormal();

			if (key == 4) {
				break;
			}

			switch (key) {
			case 1:
				majorUtil.selectAll();
				break;
			case 2:
				majorUtil.selectByName();
				break;
			case 3:
				majorUtil.update(majorUtil.select(majorUtil.input()));
				break;
			default:
				break;
			}
			System.out.println("点击回车继续...");
			sc.nextLine();
		}
	}

	/**
	 * 管理员
	 * 
	 * 学生管理
	 */
	public void stuHome() {
		StudentUtil stu = new StudentUtil();
		while (true) {
			System.out.println("**********************");
			System.out.println("请选择：");
			System.out.println("1-查看全部学生信息");
			System.out.println("2-根据姓名查找学生");
			System.out.println("3-添加学生信息");
			System.out.println("4-退出");
			System.out.println("**********************");
			int key = TestUtil.abnormal();

			if (key == 4) {

				break;
			}

			switch (key) {
			case 1:
				stu.selectAll();
				break;
			case 2:
				stu.selectByName();
				break;
			case 3:
				stu.regist();
				break;
			default:
				break;
			}
		}
	}

	/**
	 * 学生首页
	 */
	public void stuStart() {
		StudentUtil stu = new StudentUtil();
		while (true) {
			System.out.println("**********************");
			System.out.println("请选择：");
			System.out.println("1-登录");
			System.out.println("2-注册");
			System.out.println("3-退出");
			System.out.println("**********************");

			int key = TestUtil.abnormal();

			if (key == 3) {

				break;
			}

			switch (key) {
			case 1:
				stu.login();
				break;
			case 2:
				stu.regist();
				break;
			default:
				break;
			}
			System.out.println("点击回车继续...");
			sc.nextLine();
		}

	}

	public static void main(String[] args) {
		StudentTest ss = new StudentTest();
		ss.home();
	}
}
